import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/core/utils/file_util.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/equipment_start_shutdown_ledger/base_unit_stop_detail/base_unit_stop_detail_controller.dart';

/// 装置开停车大检修台账详情
class BaseUnitStopDetailPage extends StatelessWidget {
  BaseUnitStopDetailPage({super.key});

  final controller = Get.put(BaseUnitStopDetailController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      // appBar: CustomAppBar(
      //   titleText: '装置开停车大检修台账详情',
      // ),
      body: GetBuilder(
          init: controller,
          builder: (_) {
            return SingleChildScrollView(
              child: Column(
                children: [
                  _titleBg(),
                  Container(
                    height: 40.w,
                    width: double.infinity,
                    color: const Color(0xFFF4F7FF),
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.only(left: 40.w),
                    child: Text(
                      controller.data?.deviceName ?? '',
                      style: TextStyle(
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                  Container(
                    height: 1.w,
                    color: const Color(0xFFDEE5FD),
                  ),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(top: 10.w, bottom: 10.w),
                    child: Column(
                      children: [
                        _title('是否停止巡检:', controller.data?.inspectionStatus == 1 ? '开启巡检' : '停止巡检'),
                        _title('原因:', controller.data?.stopReason ?? ''),
                        _title('上传文件:', controller.data?.fileUrl ?? '').clickOnce(() {
                          FileUtils.openFile(controller.data?.fileUrl);
                        }),
                      ],
                    ),
                  ),
                ],
              ),
            );
          }),
    );
  }

  /// 标题背景分隔栏
  Widget _titleBg() {
    return Column(
      children: [
        AppGaps.vGap12,
        Container(
          height: 2.w,
          color: const Color(0xFF587DF5),
        ),
      ],
    );
  }

  /// 标题
  Widget _title(String title, String? value) {
    return Container(
      padding: EdgeInsets.only(top: 8.w, bottom: 8.w),
      child: Row(
        children: [
          AppGaps.hGap40,
          Text(
            title,
            style: TextStyle(
              color: Colors.black,
              fontSize: 12.sp,
            ),
          ),
          if (value != null)
            Expanded(
                child: Text(
              value,
              style: TextStyle(
                color: const Color(0xFF7C7D93),
                fontSize: 12.sp,
              ),
            )),
        ],
      ),
    );
  }
}
